/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package cl.tienda.control;

import cl.tienda.modelo.Producto;
import cl.tienda.modelo.Usuario;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Vector;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author 18730052-5
 */
public class ServletInicioSesion extends HttpServlet {

     Vector<Usuario> usuarios=null; //Método que va a crear dos usuarios y lo va adicionar al vector de usuarios
        public void inicializarUsuarios() { //Creando el vector de usuarios
        this.usuarios = new Vector<Usuario>(); //Creando los usuarios
                Usuario user1 = new Usuario(1, "Christoffer", "Ojeda", "cojeda", "1234", "cliente");
                Usuario user2 = new Usuario(2, "Rosa","Carreño","rcarreño","1234","empleado");
        //Adicionando los usuarios al vector de usuarios
        this.usuarios.add(user1);
        this.usuarios.add(user2);}

        Vector<Producto> productos=null; //Metodo que va a crear productos y lo va adicionar al vector de productos
        public void inicializarProductos() { //Creando el vector de usuarios
        this.productos = new Vector<Producto>(); //Creando los productos
                Producto prod1 = new Producto(1,8,"Notebook Acer",15.30f);
                Producto prod2 = new Producto(2,12,"Disco Duro Toshiba",56f);
                Producto prod3 = new Producto(3,20,"Smarth Phone Nokia Lumia 920",125.8f);
        //Adicionando los productos al vector de productos
        this.productos.add(prod1);
        this.productos.add(prod2);
        this.productos.add(prod3);}
        
    /**
     * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
     * methods.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        try (PrintWriter out = response.getWriter()) {
            
            /* TODO output your page here. You may use following sample code. */
            out.println("<!DOCTYPE html>");
            out.println("<html>");
            out.println("<head>");
            out.println("<title>Servlet ServletInicioSesion</title>");            
            out.println("</head>");
            out.println("<body>");
            out.println("<h1>Servlet ServletInicioSesion at " + request.getContextPath() + "</h1>");
            out.println("</body>");
            out.println("</html>");
        }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP <code>GET</code> method.
     *
     * @param confing
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
     @Override
    public void init(ServletConfig confing) throws ServletException {
        this.inicializarUsuarios();
        this.inicializarProductos();
        }
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Handles the HTTP <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
    
    
       
        
        
}
